
//compareFunction (ZTest)
//writeEnabled  (ZWrite)

namespace FIREFLYX {
    /** 深度状态对象 */
    export class DepthState {
        private static cacheStateMap: { [key: string]: DepthState } = {};
        private states: number[];
        // eslint-disable-next-line no-useless-constructor
        private constructor() {
            //
        }

        /** 深度比较函数 , 值为 null 关闭*/
        public get zTestCompareFunc(): Nullable<CompareFunc> { return this.states[0] == 0 ? null : this.states[0]; }
        /** 是否深度写入 */
        public get zWrite(): boolean { return this.states[1] == 1; }

        /**
         * 获取深度状态
         * @param zWrite 是否启用深度写入
         * @param zTestCFunc 深度测试比较函数(关闭给值 null)
         * @returns 深度状态对象
         */
        public static getState(zWrite = true, zTestCFunc: Nullable<CompareFunc> = CompareFunc.LESS) {
            let stateKey = `${zTestCFunc}_${zWrite}`;
            let state = this.cacheStateMap[stateKey];
            if (!state) {
                this.cacheStateMap[stateKey] = state = new DepthState();
                state.states = [zTestCFunc == null ? 0 : zTestCFunc, Number(zWrite)];
            }
            return state;
        }
    }
}